package vip

import (
	"context"

	"github.com/gogf/gf/v2/frame/g"

	"github.com/beherochuling/beesoft_api/app/dao"
	"github.com/beherochuling/beesoft_api/app/model"
	"github.com/beherochuling/beesoft_api/app/model/entity"
)

var ActivityLog = activityLog{}

type activityLog struct{}

func (*activityLog) Scan(ctx context.Context, where g.Map) *entity.VipActivityLogs {
	var activityLog *entity.VipActivityLogs

	err := dao.VipActivityLogs.Ctx(ctx).
		Where(where).
		Scan(&activityLog)
	if err != nil {
		panic(err)
	}

	return activityLog
}
func (*activityLog) Scans(ctx context.Context, where g.Map, pages ...model.Pagination) []entity.VipActivityLogs {
	var activityLogs []entity.VipActivityLogs

	m := dao.VipActivities.Ctx(ctx).
		Where(where)

	if len(pages) > 0 {
		page := pages[0]
		offset := (page.Page - 1) * page.PerPage
		m = m.Offset(offset).
			Limit(page.PerPage)
	}

	err := m.OrderDesc(dao.VipActivities.Columns().Id).
		Scan(&activityLogs)
	if err != nil {
		panic(err)
	}

	return activityLogs
}
